import 'package:dio/dio.dart';
import 'package:f_demo_two/components/shop_list.dart';
import 'package:flutter/material.dart';

class MyApp21 extends StatefulWidget {
  const MyApp21({super.key});

  @override
  State<MyApp21> createState() => _MyApp21State();
}

class _MyApp21State extends State<MyApp21> {
  List goodsList = [];

  @override
  void initState() {
    super.initState();

    getData();
  }

  void getData() async {
    Dio dio = Dio();
    final res = await dio.get('https://mock.boxuegu.com/mock/1172/orders');
    setState(() {
      goodsList = res.data;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        // 导航条
        appBar: AppBar(
          title: const Text('ListView使用',
              style: TextStyle(color: Colors.white, fontSize: 20)),
          backgroundColor: Colors.pink,
          centerTitle: true,
        ),
        // 主体区域
        body: ListView.separated(
            // 列表的每一项
            itemBuilder: (BuildContext context, int index) {
              return ShopList(goods: goodsList[index]);
            },
            separatorBuilder: (BuildContext context, int index) {
              return Container(
                height: 1,
                margin: const EdgeInsets.only(left: 10, right: 10),
                child: const Divider(
                  height: 1,
                ),
              );
            },
            itemCount: goodsList.length));
  }
}
